home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libray / libobj / instance.c < prev    next >
C/C++ Source or Header  |  1991-08-08  |  2KB  |  106 lines

  1. /*
  2.  * instance.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: instance.c,v 4.0 91/07/17 14:38:26 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    instance.c,v $
  19.  * Revision 4.0  91/07/17  14:38:26  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "geom.h"
  24. #include "instance.h"
  25.  
  26. static Methods *iInstanceMethods = NULL;
  27. static char instanceName[] = "instance";
  28.  
  29. Instance *
  30. InstanceCreate(obj)
  31. Geom *obj;
  32. {
  33.     Instance *inst;
  34.  
  35.     if (obj == (Geom *)NULL) {
  36.         RLerror(RL_WARN, "Instance of NULL?\n");
  37.         return (Instance *)NULL;
  38.     }
  39.     inst = (Instance *)share_malloc(sizeof(Instance));
  40.     inst->obj = obj;
  41.     BoundsCopy(obj->bounds, inst->bounds);
  42.     return inst;
  43. }
  44.  
  45. char *
  46. InstanceName()
  47. {
  48.     return instanceName;
  49. }
  50.  
  51.  
  52. /*
  53.  * Intersect ray & an instance by calling intersect.
  54.  */
  55. int
  56. InstanceIntersect(inst, ray, hitlist, mindist, maxdist)
  57. Instance *inst;
  58. Ray *ray;
  59. HitList *hitlist;
  60. Float mindist, *maxdist;
  61. {
  62.     return intersect(inst->obj, ray, hitlist, mindist, maxdist);
  63. }
  64.  
  65. Methods *
  66. InstanceMethods()
  67. {
  68.     /*
  69.      * Instances are special in that there is no
  70.      * "convert" method -- when created, they are passed
  71.      * a pointer to the object being instantiated.
  72.      * This means that you will need to set an instance's
  73.      * 'prims' field by hand (e.g., inst->prims = object->prims).
  74.      */
  75.     if (iInstanceMethods == (Methods *)NULL) {
  76.         iInstanceMethods = MethodsCreate();
  77.         iInstanceMethods->methods = InstanceMethods;
  78.         iInstanceMethods->create = (GeomCreateFunc *)InstanceCreate;
  79.         iInstanceMethods->name = InstanceName;
  80.         iInstanceMethods->intersect = InstanceIntersect;
  81.         iInstanceMethods->bounds = InstanceBounds;
  82.         iInstanceMethods->convert = (voidstar)NULL;
  83.         iInstanceMethods->checkbounds = FALSE;
  84.         iInstanceMethods->closed = TRUE;
  85.     }
  86.     return iInstanceMethods;
  87. }
  88.  
  89. void
  90. InstanceBounds(inst, bounds)
  91. Instance *inst;
  92. Float bounds[2][3];
  93. {
  94.     GeomComputeBounds(inst->obj);
  95.     BoundsCopy(inst->obj->bounds, inst->bounds);
  96.     BoundsCopy(inst->bounds, bounds);
  97. }
  98.  
  99. void
  100. InstanceMethodRegister(meth)
  101. UserMethodType meth;
  102. {
  103.     if (iInstanceMethods)
  104.         iInstanceMethods->user = meth;
  105. }
  106.